﻿@using FollowPeers.Models;
@model IEnumerable<FollowPeers.Models.Favourite>

@{
    //FollowPeers.Models.Favourite Model = new FollowPeers.Models.Favourite();
    ViewBag.Title = "Favourites";
    var FavSelectMode = "false";
    if(ViewBag.FavMode == "true")
    {
        FavSelectMode = "true"; 
    }
}

@{
    FollowPeers.Models.FollowPeersDBEntities followPeersDB = new FollowPeers.Models.FollowPeersDBEntities();
    string name = Membership.GetUser().UserName;
    FollowPeersDBEntities db = new FollowPeersDBEntities();
    UserProfile user = db.UserProfiles.SingleOrDefault(p => p.UserName == name);
    FollowPeers.Models.UserProfile myprofile = followPeersDB.UserProfiles.SingleOrDefault(p => p.UserName == name);
    var Fields = (from u in followPeersDB.Specializations
                  select u.Field).Distinct();


    //var Fields = followPeersDB.Specializations.Select(e => new { e.Field }).Distinct().ToList();
    List<FollowPeers.Models.PublicationModel> PublicationList = new List<FollowPeers.Models.PublicationModel>();
    List<FollowPeers.Models.Group> GroupList = new List<FollowPeers.Models.Group>();
    List<FollowPeers.Models.PatentModel> PatentList = new List<FollowPeers.Models.PatentModel>();
    List<FollowPeers.Models.Course> CourseList = new List<FollowPeers.Models.Course>();
    List<FollowPeers.Models.Jobs> JobList = new List<FollowPeers.Models.Jobs>();
    List<FollowPeers.Models.Event> EventList = new List<FollowPeers.Models.Event>();
    List<FollowPeers.Models.UserProfile> UserList = new List<FollowPeers.Models.UserProfile>();
    List<FollowPeers.Models.Favourite> FavouriteList = new List<FollowPeers.Models.Favourite>();
    string AddLink, AddName, AddType, AddTypeId;
    int ButtonCount = 1;
    string category = ViewBag.Category;
    string KeywordSearch = ViewBag.Keyword;
    List<int> FavTypes = new List<int>();

    if (ViewBag.Category != "")
    {
        if (ViewBag.Keyword == "")
        {
            if (category.Equals("*Select All*"))
            {
                PublicationList = followPeersDB.PublicationModels.ToList();
                PatentList = followPeersDB.PatentModels.ToList();
                JobList = followPeersDB.Jobs.ToList();
                CourseList = followPeersDB.Courses.ToList();
                GroupList = followPeersDB.Groups.ToList();
                EventList = followPeersDB.Events.ToList();
                UserList = followPeersDB.UserProfiles.ToList();
            }
            else
            {
                //string category = ViewBag.Category;
                PublicationList = followPeersDB.PublicationModels.Where(p => p.Tags.Any(a => a.TagName.ToLower() == category.ToLower())).ToList();
                PatentList = followPeersDB.PatentModels.Where(p => p.Tags.Any(a => a.TagName.ToLower() == category.ToLower())).ToList();
                JobList = followPeersDB.Jobs.Where(p => p.Tags.Any(a => a.TagName.ToLower() == category.ToLower())).ToList();
                CourseList = followPeersDB.Courses.Where(p => p.Tags.Any(a => a.TagName.ToLower() == category.ToLower())).ToList();
                GroupList = followPeersDB.Groups.Where(p => p.Tags.Any(a => a.TagName.ToLower() == category.ToLower())).ToList();
                EventList = followPeersDB.Events.Where(p => p.EventDesc.Contains(category)).ToList();
                //Need to make this either field or Specialization name
                UserList = followPeersDB.UserProfiles.Where((p => p.Specializations.Any(c => c.Field.Contains(category)))).ToList();
            }
        }
        else
        {
            //string KeywordSearch = ViewBag.Keyword;
            //PublicationList = followPeersDB.PublicationModels.Where(p => p.keyword.Contains(KeywordSearch)).ToList();
            PublicationList = followPeersDB.PublicationModels.Where(p => p.Tags.Any(a => a.TagName.ToLower() == KeywordSearch.ToLower())).ToList();
            PatentList = followPeersDB.PatentModels.Where(p => p.Tags.Any(a => a.TagName.ToLower() == KeywordSearch.ToLower())).ToList();
            JobList = followPeersDB.Jobs.Where(p => p.Tags.Any(a => a.TagName.ToLower() == KeywordSearch.ToLower())).ToList();
            CourseList = followPeersDB.Courses.Where(p => p.Tags.Any(a => a.TagName.ToLower() == KeywordSearch.ToLower())).ToList();
            GroupList = followPeersDB.Groups.Where(p => p.Tags.Any(a => a.TagName.ToLower() == KeywordSearch.ToLower())).ToList();
            EventList = followPeersDB.Events.Where(p => p.EventDesc.Contains(KeywordSearch)).ToList();
            UserList = followPeersDB.UserProfiles.Where((p => p.Specializations.Any(c => c.SpecializationName.Contains(KeywordSearch)))).ToList();
        }

        //To get FavouriteList for the current user
        FavouriteList = followPeersDB.Favourites.Where(p => p.UserProfile.UserProfileId == user.UserProfileId).OrderByDescending(a => a.ItemType).ToList();
    }
}


@Html.Partial("_Header")

<div class="container">
@Html.Partial("_SideBar1")
@Html.Partial("_SideBar6(Tags)")

<div class="grid_9">
    <div class="box">
        <h2 style="height: 20px">Favourites </h2>

        @using (Html.BeginForm())
        {
            @Html.ValidationSummary(true)
             
            <!DOCTYPE html>  
            <head>
                <link href="@Url.Content("~/css/bootstrap.min.css")" rel="stylesheet" type="text/css" />
                <link href="@Url.Content("~/css/bootstrap.css")" rel="stylesheet" type="text/css" />
                <link href="@Url.Content("~/css/bootstrap-responsive.css")" rel="stylesheet" type="text/css" />
                <script src="@Url.Content("~/js/jquery-1.5.1.min.js")" type="text/javascript"></script>
                @Script("jquery.validate.min.js")
                @Script("jquery.validate.unobtrusive.min.js")
                @Script("jquery.bgiframe.js")
                @Script("jquery.mcdropdown.js")
                <link rel="stylesheet" type="text/css" href="../../Content/css/jquery.mcdropdown.css" />
                <link href="../../Content/css/jquery-ui.css" rel="stylesheet" type="text/css" />
            </head>
            
            <body>
                <fieldset>
                    <br />
                    <div>
                        <h5>Search for Category or Keyword </h5>
                        @{SelectList selectList = new SelectList(@Fields);}
                        @Html.DropDownList("Category", selectList, "All Categories")    Enter Tag to Search
                        <textarea name="Keyword" rows="1"></textarea>
                        <input type="submit" name="Search" value="Search" class="btn btn-primary" />  <input type="submit" name="FavrMode" value="Select Favourites" class="btn btn-primary" />  <input style="float:right" type="submit" name="FavrModeOff" value="Favourites Selected" class="btn btn-primary" />
                    </div>

                @{
                          if (ViewBag.Search != null && ViewBag.Search == "yes")
                          {
                              if (ViewBag.Keyword == "")
                              {
                                  if (@category.Equals("*Select All*"))
                                  {<h6 style="height: 20px"> Showing All Results </h6>}
                                  else
                                  {        <h6 style="height: 20px"> Showing Results For: '@category' </h6>}
                              }
                              else
                              {
                            <h6 style="height: 20px"> Showing Results For: '@KeywordSearch' </h6>  
                              }
                          }
                 }
                <div class="tabbable">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#pane1" data-toggle="tab">Favourites</a></li>
                        <li><a href="#pane2" data-toggle="tab">Publications</a></li>
                        <li><a href="#pane3" data-toggle="tab">Patents</a></li>
                        <li><a href="#pane4" data-toggle="tab">Groups</a></li>
                        <li><a href="#pane5" data-toggle="tab">Jobs</a></li>
                        <li><a href="#pane6" data-toggle="tab">Courses</a></li>
                        <li><a href="#pane7" data-toggle="tab">Profiles</a></li>
                    </ul>

                    @Script("jquery.validate.unobtrusive.min.js")
                    @Script("jquery.bgiframe.js")
                    @Script("jquery.mcdropdown.js")
                    @Script("jquery-1.7.1.min.js")
                    <div id ="FavList">
                        <div class="tab-content">
                
                            <div id="pane1" class="tab-pane active">
                 
                                @if (FavouriteList.Count() != 0)
                                {   
                                    <div style="font-family:Verdana">
                                    <b>Number of Favourites: </b><span class="badge badge-important"> @FavouriteList.Count()</span>
                                    </div>
                                    <ul class ="nav nav-tabs nav-stacked">
                                    @foreach (var item in FavouriteList)
                                    {
                                        if ((FavTypes.Contains(item.ItemType) != true) && @item.ItemType == 6)
                                        {
                                                <li><a href ="#" style="color:darkred">Favourite Publications</a></li>
                                            FavTypes.Add(item.ItemType);
                                        }
                                        if ((FavTypes.Contains(item.ItemType) != true) && @item.ItemType == 7)
                                        {
                                                <li><a href ="#" style="color:darkred">Favourite Jobs</a></li>
                                            FavTypes.Add(item.ItemType);
                                        }
                                        if ((FavTypes.Contains(item.ItemType) != true) && @item.ItemType == 2)
                                        {
                                                <li><a href ="#" style="color:darkred">Favourite Groups</a></li>
                                            FavTypes.Add(item.ItemType);
                                        }
                                        if ((FavTypes.Contains(item.ItemType) != true) && @item.ItemType == 3)
                                        {
                                                <li><a href ="#" style="color:darkred">Favourite Events</a></li>
                                            FavTypes.Add(item.ItemType);
                                        }
                                        if ((FavTypes.Contains(item.ItemType) != true) && @item.ItemType == 4)
                                        {
                                                <li><a href ="#" style="color:darkred">Favourite Courses</a></li>
                                            FavTypes.Add(item.ItemType);
                                        }
                                        if ((FavTypes.Contains(item.ItemType) != true) && @item.ItemType == 5)
                                        {
                                                <li><a href ="#" style="color:darkred">Favourite Patents</a></li>
                                            FavTypes.Add(item.ItemType);
                                        }

                                        <li><a href=@item.ItemLink id="title1"><b>@item.ItemName</b></a></li>
                                    }
                                    </ul>
                                }
                                else
                                {
                                    <span class="label label-info">No Favourites Found</span>
                                }
                            </div>
            

                         @if (ViewBag.Search != null && ViewBag.Search == "yes")
                         {
                            <div id="pane2" class="tab-pane">
                                              
                            @if (PublicationList.Count() != 0)
                            {                 
                                <table class="span7">
                                <tr>
                                    <td>
                                        <span class="label label-info">Number of Publications Found Matching: @PublicationList.Count()</span>
                                    </td>
                                </tr>
                                @foreach (var item in PublicationList)
                                {
                                    AddLink = "/PublicationModel/Details/" + item.publicationID;
                                    AddType = "6";
                                    AddName = item.title;
                                    AddTypeId = item.publicationID.ToString();

                                    if (ViewBag.FavouriteAdded != null && ViewBag.FavouriteAdded == "true")
                                    {
                                        <p>Favourite Item has been added successfully.</p>
                                    }

                                    //<input type="hidden" name="ItemLink" value="/PublicationModel/Details/@item.publicationID"/>
                                    //<input type="hidden" name="ItemType" value="6"/>
                                    //<input type="hidden" name="ItemName" value="@item.title"/>
                                    //Model.ItemLink = "/PublicationModel/Details/" + item.publicationID;
                                    //Model.ItemType = 6;
                                    //Model.ItemName = item.title;
                                    //Model.ItemResearchInterests = "";
                                    
                                    <tr>
                                        <td>

                                                <div style="float: left;" id="Image">
                                                    <img class="mouseover" src="../../Content/images/paper_icon_large.jpg" style="margin-left: auto; margin-right: auto; width: 50px;" />
                                                </div>
                                                <div style="margin-left: 8px; float: left;">
                                                    <a href="/PublicationModel/Details/@item.publicationID" id="title"><b>@item.title</b></a>
                                                    <div id="Author">Author(s) : @item.author</div>
                                                    <div id="Year">Year of Publication : @item.year</div>
                                                </div>
                                                
                                    @{        
                                    //Show Add to Favourite Button only if not on the Favourite List already for user
                                    Favourite FoundMatch = user.Favourites.FirstOrDefault(p => p.ItemTypeId == item.publicationID && p.ItemType == 6);
                                    }
                                    @if (FoundMatch == null)
                                    {
                                        <div id= '@ButtonCount'>
                                        <input type="submit" name="@ButtonCount" value="Add To Fav" style="float: right; vertical-align:bottom; padding: 3px 8px;" class="btn btn-primary" />
                                        </div>
                                        
                                        string AddFavLink = "AddLink" + ButtonCount;
                                        <div style="visibility:hidden" id= '@AddFavLink'> @AddLink </div>
                                        string AddFavName = "AddName" + ButtonCount;
                                        <div style="visibility:hidden" id= '@AddFavName'> @AddName </div>
                                        string AddFavType = "AddType" + ButtonCount;
                                        <div style="visibility:hidden" id= '@AddFavType'> @AddType </div>
                                        string AddFavTypeId = "AddTypeId" + ButtonCount;
                                        <div style="visibility:hidden" id= '@AddFavTypeId'> @AddTypeId </div>
                                                    
                                        ButtonCount = ButtonCount + 1;
                                    }
                                <div style="float: right; margin-right: 5px; color: #888; font-size: 15px;">@Html.DisplayFor(modelItem => item.type)
                                    | @Html.DisplayFor(modelItem => item.status)  |
                                </div>
                                                
                                            <hr />
                                        </td>
                                    </tr>
               
                                }
                                </table>
                            }
                            else
                            {
                                                    <span class="label label-info">No Matching Publication Items Found</span>
                            }
                                                
                            </div>
                             
                            <div id="pane3" class="tab-pane">
                            @if (PatentList.Count() != 0)
                            {                 
                                <table class="span7">
                                <tr>
                                    <td>
                                        <span class="label label-info">Number of Patents Found Matching: @PatentList.Count()</span>
                                    </td>
                                </tr>
                                @foreach (var item in PatentList)
                                {
                                    AddLink = "/PatentModel/Details/" + item.ID;
                                    AddType = "5";
                                    AddName = item.Title;
                                    AddTypeId = item.ID.ToString();

                                    if (ViewBag.FavouriteAdded != null && ViewBag.FavouriteAdded == "true")
                                    {
                                        <p>Favourite Item has been added successfully.</p>
                                    }

                                    //<input type="hidden" name="ItemLink" value="/PublicationModel/Details/@item.publicationID"/>
                                    //<input type="hidden" name="ItemType" value="6"/>
                                    //<input type="hidden" name="ItemName" value="@item.title"/>
                                    //Model.ItemLink = "/PublicationModel/Details/" + item.publicationID;
                                    //Model.ItemType = 6;
                                    //Model.ItemName = item.title;
                                    //Model.ItemResearchInterests = "";
                                    
                                    <tr>
                                        <td>

                                                <div style="float: left;" id="Image">
                                                    <img class="mouseover" src="../../Content/images/paper_icon_large.jpg" style="margin-left: auto; margin-right: auto; width: 50px;" />
                                                </div>
                                                <div style="margin-left: 8px; float: left;">
                                                    <a href="/PatentModel/Details/@item.ID" id="title"><b>@item.Title</b></a>
                                                    @{if (item.About != null)
                                                      {<div id="PatentDesc">Description : @item.About</div>}}
                                                </div>
                                                
                                    @{        
                                                      //Show Add to Favourite Button only if not on the Favourite List already for user
                                                      Favourite FoundMatch = user.Favourites.FirstOrDefault(p => p.ItemTypeId == item.ID && p.ItemType == 5);
                                    }
                                    @if (FoundMatch == null)
                                    {
                                        string PatentDivId = "PatentDiv" + ButtonCount;
                                        <div id= '@PatentDivId'>
                                        <input type="submit" name="@PatentDivId" value="Add To Fav" style="float: right; vertical-align:bottom; padding: 3px 8px;" class="btn btn-primary" />
                                        </div>
                                        
                                        string PatentFavLink = "AddLink" + PatentDivId;
                                        <div style="visibility:hidden" id= '@PatentFavLink'> @AddLink </div>
                                        string PatentFavName = "AddName" + PatentDivId;
                                        <div style="visibility:hidden" id= '@PatentFavName'> @AddName </div>
                                        string PatentFavType = "AddType" + PatentDivId;
                                        <div style="visibility:hidden" id= '@PatentFavType'> @AddType </div>
                                        string PatentFavTypeId = "AddTypeId" + PatentDivId;
                                        <div style="visibility:hidden" id= '@PatentFavTypeId'> @AddTypeId </div>
                                                    
                                        ButtonCount = ButtonCount + 1;
                                    }
                                                
                                            <hr />
                                        </td>
                                    </tr>
               
                                }
                                </table>
                            }
                            else
                            {
                                                    <span class="label label-info">No Matching Patent Items Found</span>
                            }

                            </div>
                                
                            <div id="pane4" class="tab-pane">
                                @if (GroupList.Count() != 0)
                                {                 
                                    <table class="span7">
                                    <tr>
                                        <td>
                                            <span class="label label-info">Number of Groups Found Matching: @GroupList.Count()</span>
                                        </td>
                                    </tr>
                                    @foreach (var item in GroupList)
                                    {
                                        AddLink = "/Groups/Details/" + item.GroupId;
                                        AddType = "2";
                                        AddName = item.Name;
                                        AddTypeId = item.GroupId.ToString();

                                        if (ViewBag.FavouriteAdded != null && ViewBag.FavouriteAdded == "true")
                                        {
                                            <p>Favourite Item has been added successfully.</p>
                                        }

                                        //<input type="hidden" name="ItemLink" value="/PublicationModel/Details/@item.publicationID"/>
                                        //<input type="hidden" name="ItemType" value="6"/>
                                        //<input type="hidden" name="ItemName" value="@item.title"/>
                                        //Model.ItemLink = "/PublicationModel/Details/" + item.publicationID;
                                        //Model.ItemType = 6;
                                        //Model.ItemName = item.title;
                                        //Model.ItemResearchInterests = "";
                                    
                                        <tr>
                                            <td>

                                                    <div style="float: left;" id="Image">
                                                        <img class="mouseover" src="../../Content/images/paper_icon_large.jpg" style="margin-left: auto; margin-right: auto; width: 50px;" />
                                                    </div>
                                                    <div style="margin-left: 8px; float: left;">
                                                        <a href="/Groups/Details/@item.GroupId" id="title"><b>@item.Name</b></a>
                                                        @if (@item.GroupDesc != null)
                                                        {<div id="GroupDesc">Decription(s) : @item.GroupDesc</div>}
                                                        @if (item.Tags != null)
                                                        {
                                                            <div id="GroupTags"> Tags
                                                            @foreach (Tag i in item.Tags)
                                                            {
                                                               <text>i.TagName</text>
                                                            }
                                                            </div>
                                                        }
                                                    </div>
                                                
                                        @{        
                                                        //Show Add to Favourite Button only if not on the Favourite List already for user
                                                        Favourite FoundMatch = user.Favourites.FirstOrDefault(p => p.ItemTypeId == item.GroupId && p.ItemType == 2);
                                        }
                                        @if (FoundMatch == null)
                                        {
                                            string GroupDivId = "GroupDiv" + ButtonCount;
                                            <div id= '@GroupDivId'>
                                            <input type="submit" name="@GroupDivId" value="Add To Fav" style="float: right; vertical-align:bottom; padding: 3px 8px;" class="btn btn-primary" />
                                            </div>
                                        
                                            string GroupFavLink = "AddLink" + GroupDivId;
                                            <div style="visibility:hidden" id= '@GroupFavLink'> @AddLink </div>
                                            string GroupFavName = "AddName" + GroupDivId;
                                            <div style="visibility:hidden" id= '@GroupFavName'> @AddName </div>
                                            string GroupFavType = "AddType" + GroupDivId;
                                            <div style="visibility:hidden" id= '@GroupFavType'> @AddType </div>
                                            string GroupFavTypeId = "AddTypeId" + GroupDivId;
                                            <div style="visibility:hidden" id= '@GroupFavTypeId'> @AddTypeId </div>
                                                    
                                            ButtonCount = ButtonCount + 1;
                                        }
                                                
                                                <hr />
                                            </td>
                                        </tr>
               
                                    }
                                    </table>
                                }
                                else
                                {
                                                        <span class="label label-info">No Matching Group Items Found</span>
                                }
                                                
                            </div>
                            <div id="pane5" class="tab-pane">
                            @if (JobList.Count() != 0)
                            {                 
                                <table class="span7">
                                <tr>
                                    <td>
                                        <div style="font-family:Verdana">
                                        <b>Number of Jobs Found Matching: </b><span class="badge badge-important">@JobList.Count()</span>
                                        </div>
                                    </td>
                                </tr>
                                @foreach (var item in JobList)
                                {
                                    AddLink = "/Jobs/Details/" + item.JobId;
                                    AddType = "7";
                                    AddName = item.Title;
                                    AddTypeId = item.JobId.ToString();

                                    if (ViewBag.FavouriteAdded != null && ViewBag.FavouriteAdded == "true")
                                    {
                                        <p>Favourite Item has been added successfully.</p>
                                    }
                                    
                                    <tr>
                                        <td>

                                                <div style="float: left;" id="Image">
                                                    <img class="mouseover" src="../../Content/images/paper_icon_large.jpg" style="margin-left: auto; margin-right: auto; width: 50px;" />
                                                </div>
                                                <div style="margin-left: 8px; float: left;">
                                                    <a href="/Jobs/Details/@item.JobId" id="jobtitle"><b>@item.Title</b></a>
                                                    <div id="jobpubdate">Published Date : @item.publishDate</div>
                                                    <div id="jobcompany">Company : @item.Company</div>
                                                </div>
                                                
                                    @{        
                                    //Show Add to Favourite Button only if not on the Favourite List already for user
                                    Favourite FoundMatch = user.Favourites.FirstOrDefault(p => p.ItemTypeId == item.JobId && p.ItemType == 7);
                                    }
                                    @if (FoundMatch == null)
                                    {
                                        string JobDivId = "JobDiv" + ButtonCount;
                                        <div id= '@JobDivId'>
                                        <input type="submit" name="@JobDivId" value="Add To Fav" style="float: right; vertical-align:bottom; padding: 3px 8px;" class="btn btn-primary" />
                                        </div>
                                        
                                        string AddFavJobLink = "AddLink" + JobDivId;
                                        <div style="visibility:hidden" id= '@AddFavJobLink'> @AddLink </div>
                                        string AddFavJobName = "AddName" + JobDivId;
                                        <div style="visibility:hidden" id= '@AddFavJobName'> @AddName </div>
                                        string AddFavJobType = "AddType" + JobDivId;
                                        <div style="visibility:hidden" id= '@AddFavJobType'> @AddType </div>
                                        string AddFavJobTypeId = "AddTypeId" + JobDivId;
                                        <div style="visibility:hidden" id= '@AddFavJobTypeId'> @AddTypeId </div>
                                                    
                                        ButtonCount = ButtonCount + 1;
                                    }
                                                
                                            <hr />
                                        </td>
                                    </tr>
               
                                }
                                </table>
                            }
                            else
                            {
                                 <span class="label label-info">No Matching Job Items Found</span>
                            }
                                                
                            </div>
                             
                            <div id="pane6" class="tab-pane">
                            @if (CourseList.Count() != 0)
                            {                 
                                <table class="span7">
                                <tr>
                                    <td>
                                        <div style="font-family:Verdana">
                                        <b>Number of Courses Found Matching: </b><span class="badge badge-important">@CourseList.Count()</span>
                                        </div>
                                    </td>
                                </tr>
                                @foreach (var item in CourseList)
                                {
                                    AddLink = "/Courses/Details/" + item.CourseId;
                                    AddType = "4";
                                    AddName = item.CourseName;
                                    AddTypeId = item.CourseId.ToString();

                                    if (ViewBag.FavouriteAdded != null && ViewBag.FavouriteAdded == "true")
                                    {
                                        <p>Favourite Item has been added successfully.</p>
                                    }
                                    
                                    <tr>
                                        <td>

                                                <div style="float: left;" id="Image">
                                                    <img class="mouseover" src="@item.PhotoUrl" style="margin-left: auto; margin-right: auto; width: 50px;" />
                                                </div>
                                                <div style="margin-left: 8px; float: left;">
                                                    <a href="/Jobs/Details/@item.CourseId" id="jobtitle"><b>@item.CourseName</b></a>
                                                    @if (@item.Owner.FirstName != null)
                                                    {<div id="Coursecreate">Created By: @item.Owner.FirstName @item.Owner.LastName</div>}
                                                    @if (@item.Tags != null)
                                                    {
                                                        <div id="CourseTags"> Tags
                                                            @foreach (Tag i in item.Tags)
                                                            {
                                                               <text>i.TagName</text>
                                                            }
                                                            </div>
                                                    }
                                                </div>
                                                
                                    @{        
                                                    //Show Add to Favourite Button only if not on the Favourite List already for user
                                                    Favourite FoundMatch = user.Favourites.FirstOrDefault(p => p.ItemTypeId == item.CourseId && p.ItemType == 4);
                                    }
                                    @if (FoundMatch == null)
                                    {
                                        string CourseDivId = "CourseDiv" + ButtonCount;
                                        <div id= '@CourseDivId'>
                                        <input type="submit" name="@CourseDivId" value="Add To Fav" style="float: right; vertical-align:bottom; padding: 3px 8px;" class="btn btn-primary" />
                                        </div>
                                        
                                        string AddFavCourseLink = "AddLink" + CourseDivId;
                                        <div style="visibility:hidden" id= '@AddFavCourseLink'> @AddLink </div>
                                        string AddFavCourseName = "AddName" + CourseDivId;
                                        <div style="visibility:hidden" id= '@AddFavCourseName'> @AddName </div>
                                        string AddFavCourseType = "AddType" + CourseDivId;
                                        <div style="visibility:hidden" id= '@AddFavCourseType'> @AddType </div>
                                        string AddFavCourseTypeId = "AddTypeId" + CourseDivId;
                                        <div style="visibility:hidden" id= '@AddFavCourseTypeId'> @AddTypeId </div>
                                                    
                                        ButtonCount = ButtonCount + 1;
                                    }
                                                
                                            <hr />
                                        </td>
                                    </tr>
               
                                }
                                </table>
                            }
                            else
                            {
                                 <span class="label label-info">No Matching Courses Found</span>
                            }
                            </div>

                            <div id="pane7" class="tab-pane">
                            @{
                            if (UserList.Count() != 0)
                            {
                                    <table class="span7">
                                    <tr>
                                        <td>
                                            <span class="label label-info">Number of Profiles Found Matching: @UserList.Count()</span>
                                        </td>
                                    </tr>
                                    @foreach (var item in UserList)
                                    {
                                        <tr>
                                            <td>

                                                <div style="border-bottom: 1px solid grey; margin: 10px 0px;">
                                                    <div style="margin-left: 8px; float: left;">
                                                        <a href="/Profile/Index/@item.UserProfileId" id="title"><b>@item.FirstName @item.LastName</b></a>
                                                        @{
                                        if (@item.Specializations != null)
                                        {
                                                                <br />
                                                                <text>Research Interests:</text>
                                            foreach (var spec in item.Specializations)
                                            {
                                                                   <div id="Specialization"> <a href="/Forum/CategoryDetail/?Category=@spec.Field"> @spec.SpecializationName</a> </div>
                                            }
                                        }
                                                         }
                                                    </div>
                                                </div>
                                                <hr />
                                            </td>
                                        </tr>
                                    }
                                    </table>
                            }
                            else
                            {
                                        <span class="label label-info">No Users Found</span>
                            }
                              }
                            </div>
                         }
                        
                        </div>
                        <!-- /.tab-content -->
                    </div> <!--End of Fav List Div to keep track of button press -->
                </div>
                <!-- /.tabbable -->
                
                </fieldset>
                <script src="http://code.jquery.com/jquery.js"></script>
                <script src="@Url.Content("~/js/bootstrap.min.js")"></script>

            </body>               
        }
        
    </div>
</div>
    </div>

@Html.Partial("_Footer")

@helper Script(string scriptName)
{
    <script src="@Url.Content("~/Scripts/" + scriptName)" type="text/javascript"></script>
}
<script type="text/javascript" language="javascript">

    window.FavSelectMode = @(FavSelectMode)

    $(document).ready(function () {
        $('#Keyword').hide();
        $('#Journal').hide();
        $('#Conference').hide();
        $('#University').hide();

        $(".collapse").collapse();
    });

    
    $('#FavList').click(function (e) {
        if (window.FavSelectMode == true) {
            e.preventDefault();
            var button = e.target;
            $.ajax({
                url: '/Favourites/AddFav',
                type: 'POST',
                data: { AddLink: $('#AddLink' + button.name).text().toString(), AddName: $('#AddName' + button.name).text().toString(), AddType: $('#AddType' + button.name).text().toString(), AddTypeId: $('#AddTypeId' + button.name).text().toString() },
                success: function () {
                    alert("Done:" + input.name);
                },
                error: function () {
                    alert("Error Creating Favourite. Try Again.");
                }
            });
        }
        });

    $('.carousel').carousel({
        interval: 2000
    });
    $('#myModal').modal()
    $('#myModal').modal('hide')

    $('#Image').mouseover(function () {
        $('#Keyword').slideDown("fast");
        $('#Journal').slideDown("fast");
        $('#Conference').slideDown("fast");
        $('#University').slideDown("fast");
    });
    $('#Image').mouseout(function () {
        $('#Keyword').hide();
        $('#Journal').hide();
        $('#Conference').hide();
        $('#University').hide();
    });
    function tab(tab) {
        document.getElementById('tab1').style.display = 'none';
        document.getElementById('tab2').style.display = 'none';
        document.getElementById('tab3').style.display = 'none';
        document.getElementById('tab4').style.display = 'none';
        document.getElementById('li_tab1').setAttribute("class", "");
        document.getElementById('li_tab2').setAttribute("class", "");
        document.getElementById('li_tab3').setAttribute("class", "");
        document.getElementById('li_tab4').setAttribute("class", "");
        document.getElementById(tab).style.display = 'block';
        document.getElementById('li_' + tab).setAttribute("class", "active");
    }

</script>




